<?php

class Controller_Contact extends Controller_Website
{

	public function actionIndex()
	{
		$this->template->title = $this->settings['title'];
		$this->template->content = new View('contact/index');
                $contact = $this->manager->getText('contact');
                $this->template->content->contact = $contact;
	}
        
        public function actionContact()
        {
            $this->autoRender = FALSE;
            $emailArr = $this->db->query("SELECT value FROM settings WHERE `key`='email'")->fetch();
            $exitEmail = $emailArr['value'];
            
            if(Request::$isAjax)
            {
                $email = Request::get('email');
                $message = Request::get('message');
                $message = strip_tags(trim($message));
                $subject = Request::get('subject');
                   
                $msg =  '';
                $msg .= 'You have new message from:' . "\n\n";
                $msg .= 'Email: '.$email . "\n";
                $msg .= 'Message:' . "\n" . $message;

                if(Validate::email($email) &&$message !== '')
                {
                   Mailer::sendMail($exitEmail, $subject, $msg, $this->settings['title'].'<noreply@'.$_SERVER['HTTP_HOST'].'>');
                 
                }
                else
                {
                   echo 'Information is not valid.Please try ag';
                }
            }
            
        }
}

